-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deck: Assigned unique id to each card. #14
Conversation
fd7e42b
to
77ea2e9
Compare
backend/uno-game-engine/deck.js
Outdated
@@ -60,7 +60,16 @@ export default function getShuffledCardDeck() { | |||
*/ | |||
function makeCard(type, color, value) { | |||
//todo: Implement unique identification of cards by assigning an id to each card | |||
return { type, color, value }; | |||
let card_num = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The card_num array will be lost when the function returns. We'd need to persist the array data across multiple function calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I realized my mistake later. I have corrected it; please review the updated version.
77ea2e9
to
9cfc7ae
Compare
f828c52
to
a008630
Compare
@sethdivyansh Please rebase your branch against I'l merge it then. |
9cfc7ae
to
91d4931
Compare
@kuv2707 I have resolved all the conflicts. Please review the PR and merge it. |
35ad142
to
7bf32c6
Compare
backend/uno-game-engine/deck.ts
Outdated
@@ -57,7 +58,13 @@ export default function getShuffledCardDeck(): Array<UNOCard> { | |||
*/ | |||
function makeCard(type: CardType, color: CardColor, value: CardValue): UNOCard { | |||
//todo: Implement unique identification of cards by assigning an id to each card | |||
return { type, color, value, id: undefined }; | |||
let id = `card-${type}-${color}-${value}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer const for variables which do not change. Eslint should have given an error.
backend/uno-game-engine/deck.ts
Outdated
if (!sameCardCount[id]) sameCardCount[id] = 0; | ||
sameCardCount[id]++; // increment the count of same cards to assign unique id | ||
|
||
let uid = `${id}-${sameCardCount[id]}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
7bf32c6
to
c851162
Compare
@kuv2707 I have made all the changes. |
@sethdivyansh Please add the "Fixes" clause in the commit message. |
c851162
to
c1943b7
Compare
@kuv2707 Done |
@sethdivyansh Please add the motivation to use a custom-generated ID instead of approaches like uuid etc in the PR description. This PR is ready to be merged. Will do it once the event begins officially. |
@kuv2707 @shivansh-bhatnagar18 I have mentioned the reasons for choosing custom IDs. If you feel using UUIDs is a better approach, please let me know, and I will make the desired changes accordingly. |
No, this approach is fine. I just wanted you to mention the reasoning in the PR description for future reference. |
backend/uno-game-engine/deck.ts
Outdated
@@ -57,7 +58,13 @@ export default function getShuffledCardDeck(): Array<UNOCard> { | |||
*/ | |||
function makeCard(type: CardType, color: CardColor, value: CardValue): UNOCard { | |||
//todo: Implement unique identification of cards by assigning an id to each card |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sethdivyansh Remove this todo comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed the comment.
c1943b7
to
c122a60
Compare
638c172
to
aad9592
Compare
- Created an ID in the format `card-type-color-value`. - Added a `sameCardCount` array to uniquely identify cards of the same type and color. - Generated a unique ID using the format `card-type-color-value-sameCardCount[id]`. Fixes shivansh-bhatnagar18#4
aad9592
to
81d9652
Compare
Merged, thanks @sethdivyansh ! |
card-type-color-value
.sameCardCount
array to uniquely identify cards of the same type and color.card-type-color-value-sameCardCount[id]
.Fixes #4
Reason for choosing custom unique id instead of UUID etc
card-Special-Red-skip-2
immediately conveys that the card is a red "skip" card and it is the second one of its kind.card-Special-Red-skip-2
arehuman-readable
, making it easier for developers and testers to trace issues, verify game logic, and understand game states during testing and development.UUIDs
, being long and non-descriptive,lack this readability
.Self-review checklist
Completed manual review and testing of the following: